package com.atguigu.controller;

import com.atguigu.Msg;
import com.atguigu.bean.Student;
import com.atguigu.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

//处理员工CRUD请求
@Controller
public class StudentController {

    @Autowired
    StudentService studentService;
    /**
     * 查询员工信息
     * @return
     */

    @RequestMapping("/stu")
    @ResponseBody
    public Msg getStusWithJson(@RequestParam(value = "pn",defaultValue = "1")Integer pn){
        PageHelper.startPage(pn,5);
        List<Student> all = studentService.getAll();
        PageInfo page = new PageInfo(all,5);
        return Msg.success().add("pageInfo",page);
    }


//    @RequestMapping("/stu")
//    public String Stu(@RequestParam(value = "pn",defaultValue = "1")Integer pn,Model model) {
//        //分页
//        PageHelper.startPage(pn,5);
//        List<Student> all = studentService.getAll();
//        PageInfo page = new PageInfo(all,5);
//        model.addAttribute("pageInfo",page);
//        return "list";
//    }
}
